package cn.stylefeng.guns.sys.modular.system.controller;

import cn.hutool.core.collection.CollectionUtil;
import cn.stylefeng.guns.base.pojo.page.LayuiPageInfo;
import cn.stylefeng.guns.sys.modular.system.model.params.SalaryChangeParam;
import cn.stylefeng.guns.sys.modular.system.service.BtySalaryChangeService;
import cn.stylefeng.roses.core.reqres.response.ResponseData;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.util.ObjectUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 *
 * 工资变动主表控制层
 *
 * @author: tianzhen
 * @date: 2022/7/14 14:54
 */

@Controller
@RequestMapping("/btySalaryChange")
public class BtySalaryChangeController {

    private String PREFIX = "/modular/system/btySalaryChange";

    @Resource
    private BtySalaryChangeService salaryChangeInfoService;

    /**
     * 跳转到主页面
     *
     * @author yxc
     * @Date 2021-05-13
     */
    @RequestMapping("")
    public String index() {
        return PREFIX + "/salaryChange.html";
    }

    /**
     * 获取所有的营运经理列表
     *
     * @param:  salaryChangeParam 查询条件
     * @return:
     */
    @RequestMapping("/getOperationManagerList")
    @ResponseBody
    public ResponseData getOperationManagerList(SalaryChangeParam salaryChangeParam) {
        return ResponseData.success(salaryChangeInfoService.getOperationManagerList(salaryChangeParam));
    }

    /**
     * 获取督导列表根据营运经理
     *
     * @param:  salaryChangeParam 查询条件
     * @return:
     */
    @RequestMapping("/getSupervisorList")
    @ResponseBody
    public ResponseData getSupervisorList(SalaryChangeParam salaryChangeParam) {
        return ResponseData.success(salaryChangeInfoService.getSupervisorList(salaryChangeParam));
    }

    /**
     * 获取店铺列表根据督导
     *
     * @param:  salaryChangeParam 查询条件
     * @return:
     */
    @RequestMapping("/getStoreList")
    @ResponseBody
    public ResponseData getStoreList(SalaryChangeParam salaryChangeParam) {
        return ResponseData.success(salaryChangeInfoService.getStoreList(salaryChangeParam));
    }

    /**
     * 获取店铺的员工
     *
     * @param:  salaryChangeParam 查询条件
     * @return:
     */
    @RequestMapping("/getEmpListByStoreName")
    @ResponseBody
    public ResponseData getEmpListByStoreName(SalaryChangeParam salaryChangeParam) {
        return ResponseData.success(salaryChangeInfoService.getEmpListByStoreName(salaryChangeParam));
    }


    /**
     * 申请单列表分页查询(分页)
     *
     * @param:  salaryChangeParam 查询条件
     * @return:
     */
    @RequestMapping("/getSalaryChangePage")
    @ResponseBody
    public LayuiPageInfo getSalaryChangePage(SalaryChangeParam salaryChangeParam) {
        LayuiPageInfo pageResult = salaryChangeInfoService.getSalaryChangePage(salaryChangeParam);
        return pageResult;
    }

    /**
     * 工资变动申请审核
     *
     * @param:  salaryChangeParam  审核的申请单id集合
     * @return:
     *
     */
    @RequestMapping("/batchAudit")
    @ResponseBody
    public ResponseData audit(SalaryChangeParam salaryChangeParam) {
        if(CollectionUtil.isEmpty(salaryChangeParam.getIdList())){
            return ResponseData.error(1001, "参数审核的单据id不能为空");
        }
        if(ObjectUtils.isEmpty(salaryChangeParam.getAuditStatus())){
            return ResponseData.error(1001, "参数审核状态不能为空");
        }
        return salaryChangeInfoService.audit(salaryChangeParam);
    }

    /**
     * 导出excel表格
     *
     * @param:  salaryChangeParam 查询条件
     * @return:
     */
    @RequestMapping("/EmpSalaryChangeDataExport")
    @ResponseBody
    public ResponseEntity<byte[]> EmpSalaryChangeDataExport(HttpServletRequest request, HttpServletResponse response, SalaryChangeParam salaryChangeParam) {
        return salaryChangeInfoService.EmpSalaryChangeDataExport(request, response, salaryChangeParam);
    }

}
